package com.layblog.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * RabbitMqConfig配置
 *
 * @Author 林必昭
 * @Date 2021/9/8 19:06
 */

@Configuration
public class RabbitMqConfig {

    //队列名称
    public static final String ES_QUEUE = "my-mq-es_queue";
    public static final String ES_EXCHANGE = "my-mq-es_exchange";
    public static final String ES_BIND_KEY = "my-mq-es_index_message";


    /**
     * 声明队列
     *
     * @return
     */
    @Bean
    public Queue esQueue() {
        return new Queue(ES_QUEUE);
    }

    /**
     * 声明交换机
     *
     * @return
     */
    @Bean
    DirectExchange esExchange() {
        return new DirectExchange(ES_EXCHANGE);
    }

    /**
     * 绑定交换机和队列，将队列queue按照路由规则绑定到交换机exchange当中
     *
     * @param esQueue
     * @param esExchange
     * @return
     */
    @Bean
    Binding bindingExchangeMessage(Queue esQueue, DirectExchange esExchange) {
        return BindingBuilder.bind(esQueue).to(esExchange).with(ES_BIND_KEY);
    }


}
